0401a83f05384e5acfb8f308bf5287f4ceb69f73,src/main/org/codehaus/groovy/classgen/ReflectorGenerator.java,ReflectorGenerator,generateInvokeMethod,#,92
Before Change
protected void generateInvokeMethod() {
int methodCount = methods.size();
cv =
cw.visitMethod(
ACC_PUBLIC,
"invoke",
"(Lgroovy/lang/MetaMethod;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;",
null,
null);
helper = new BytecodeHelper(cv);
cv.visitVarInsn(ALOAD, 1);
cv.visitMethodInsn(INVOKEVIRTUAL, "groovy/lang/MetaMethod", "getMethodIndex", "()I");
Label defaultLabel = new Label();
Label[] labels = new Label[methodCount];
int[] indices = new int[methodCount];
for (int i = 0; i < methodCount; i++) {
labels[i] = new Label();
MetaMethod method = (MetaMethod) methods.get(i);
method.setMethodIndex(i + 1);
indices[i] = method.getMethodIndex();
//System.out.println("Index: " + method.getMethodIndex() + " for: " + method);
}
cv.visitLookupSwitchInsn(defaultLabel, indices, labels);
//cv.visitTableSwitchInsn(minMethodIndex, maxMethodIndex, defaultLabel, labels);
for (int i = 0; i < methodCount; i++) {
cv.visitLabel(labels[i]);
MetaMethod method = (MetaMethod) methods.get(i);
invokeMethod(method);
if (method.getReturnType() == void.class) {
cv.visitInsn(ACONST_NULL);
}
cv.visitInsn(ARETURN);
}
cv.visitLabel(defaultLabel);
cv.visitVarInsn(ALOAD, 0);
cv.visitVarInsn(ALOAD, 1);
cv.visitVarInsn(ALOAD, 2);
cv.visitVarInsn(ALOAD, 3);
cv.visitMethodInsn(
INVOKEVIRTUAL,
After Change
// load parameters for the helper method call
cv.visitVarInsn(ALOAD, 0);
cv.visitVarInsn(ALOAD, 1);
cv.visitVarInsn(ALOAD, 2);
cv.visitVarInsn(ALOAD, 3);
// get method number for switch